import Info.SystemEnum;
import pojo.*;
import db.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

public class MainSystem {
    //输入对象
    Scanner scanner;
    //用户身份
    private int status;     //0-游客  1-普通用户  2-管理员   -1--初始
    //当前登陆的用户
    User nowUser;
    //菜单属性
    private String mainMenu;        //0
    private String domesticMenu;    //1
    private String adminMenu;       //2
    //数据库
    DataBase dataBase;
    //管理集合
    ManageBrandDB manageBrandDB;
    ManageCarDB manageCarDB;
    ManageCarTypeDB manageCarTypeDB;
    ManageCollectDB manageCollectDB;
    ManageContrastDB manageContrastDB;
    ManageUserDB manageUserDB;
    //日志
    Log log;



    ///////////////////////////////////////////////////////程序入口
    public static void main(String[] args) {
        MainSystem mainSystem = new MainSystem();
        mainSystem.start();
    }
    //////////////////////////////////////////////////////////////


    //初始化系统--初始化系统属性
    public MainSystem() {
        //初始化log
        log = LogFactory.getLog(MainSystem.class);
        log.info(" MainSystem()-系统开始初始化");
        //初始化输入
        scanner = new Scanner(System.in);

        //初始化用户身份
        status = -1;
        //初始化数据库db
        dataBase = DataBase.getInstance();
        //初始化数据库管理
        manageBrandDB = new ManageBrandDB(log);
        manageCarDB = new ManageCarDB(log);
        manageCarTypeDB = new ManageCarTypeDB(log);
        manageCollectDB = new ManageCollectDB(log);
        manageContrastDB = new ManageContrastDB(log);
        manageUserDB = new ManageUserDB(log);
        //初始化菜单属性
        mainMenu = "1.登陆\n" +
                "2.注册：用户名不能重复\n" +
                "3.最新二手车信息\n" +
                "4.搜索车辆\n" +
                "5.退出系统";
        domesticMenu = "1.对比车辆\n" +
                "2.我的收藏\n" +
                "3.退出到上一级";

        adminMenu = "1.后台管理\n" +
                "2.退出到上一级";
        status = 0;
        log.info(" MainSystem()-系统初始化完成");
    }

    //菜单方法--根据身份显示
    public void menu(){
        log.info("status = "+status);
        switch (status){
            case 0:
                log.info("当前所在菜单为：游客界面");
                System.out.println(mainMenu);
                break;
            case 1:
                log.info("当前所在菜单为：普通用户界面");
                System.out.println(domesticMenu);
                break;
            case 2:
                log.info("当前所在菜单为：管理员界面");
                System.out.println(adminMenu);
                break;
        }
    }

    public void menu(String mainStr){
        log.info("status = "+status);
        System.out.println(mainStr);
    }

    //判断用户身份
    public boolean check(){
        //用户一定存在
        if (nowUser.getPower()==1){//power为1代表是管理员
            return true;
        }else {//power为0代表是普通用户
            return false;
        }
    }
    //开始方法--接受-选择信息
    public void start(){
        log.info(" MainSystem--start()");
        int chose = -1; //-1为初始状态   -2为结束状态
        try {
            while (chose!=-2){
                menu();
                chose = scanner.nextInt();
                switch (chose){
                    case 1:
                        if(login()){
                            //登陆成功
                            log.info(SystemEnum.SUCCESS.toString());
                            //status = 1;
                            //判断是否既是普通用户又是管理员
                            if(check()){   //判断是否同时具有管理员身份
                               System.out.println("请选择以普通用户登录（true）还是管理员身份登陆（false）");
                                try {
                                    boolean chose2 = scanner.nextBoolean();
                                    status = chose2 ? 1:2;
                                }catch (Exception e){
                                    System.out.println("输入错误,登陆失败，返回主界面");
                                    status = 0;
                                    //吸收输入错误的字符内容
                                    String errorInput = scanner.nextLine();
                                    log.info(SystemEnum.ERROR_INPUT.toString()+"\t内容:"+errorInput);
                                    break;
                                }
                            }
                            if(status==1) startDomestic();
                            if(status==2) startAdmin();
                        }else log.info(SystemEnum.ERROR_INEFFECTIVE.toString());
                        break;
                    case 2:
                        if(signin()) log.info(SystemEnum.SUCCESS.toString());
                        else log.info(SystemEnum.ERROR_INEFFECTIVE.toString());
                        break;
                    case 3:
                        printNewUsedCarInfo();
                        break;
                    case 4:
                       // findACar(manageCarDB.getCarsList());
                        findACar();
                        break;
                    default:
                    case 5:
                        chose = -2;
                        log.info("准备退出系统--"+SystemEnum.SUCCESS.toString());
                        break;
                }
            }
        }catch (Exception e){
            String errorInput = scanner.nextLine();
            log.info(SystemEnum.ERROR_INPUT+errorInput);
        }finally {
            end();
        }
    }



    //以普通用户登陆--开始
    public void startDomestic(){
        log.info("进入普通用户菜单");
        int chose = -1; //-1为初始状态   -2为结束状态
        while (chose!=-2){
            menu();
            chose = scanner.nextInt();
            switch (chose){
                case 1:
                    contrastCars();
                    break;
                case 2:
                    myCollect();
                    break;
                case 3:
                default:
                    chose = -2;
                    status = 0;
                    log.info("退出普通用户菜单");
                    break;
            }
        }
    }

    //以管理员登陆--开始
    public void startAdmin(){
        log.info("进入管理员菜单");
        int chose = -1; //-1为初始状态   -2为结束状态
        while (chose!=-2){
            menu();
            chose = scanner.nextInt();
            switch (chose){
                case 1:
                    management();
                    break;
                case 2:
                default:
                    chose = -2;
                    status = 0;
                    log.info("退出管理员菜单");
                    break;
            }
        }
    }
    //结束方法--结束输入，显示结束语
    public void end(){
        scanner.close();
        System.out.println("欢迎下次使用该系统");
        log.info("退出系统成功--"+SystemEnum.SUCCESS.toString());
    }

    public boolean login(){     //登陆
        log.info("MainSystem--login()");
        //如果登陆成功则把设置为status = 1;

        //登陆
        boolean flag = false;
        System.out.println("姓名 ：");
        String username = scanner.next();

        System.out.println("密码：");
        String password = scanner.next();

        // 验证码
        int num = (int) (Math.random()*9000)+1000;
        System.out.println("验证码:" + num);
        System.out.println("输入上面出现的验证码:");
        int inputNum;
        try{
            inputNum = scanner.nextInt();
        }catch (Exception e){
            System.out.println("验证码输出格式有误，退出登陆");
            String errorInput = scanner.nextLine();
            log.info(SystemEnum.ERROR_INPUT+errorInput);
            return false;
        }

        //核对正确的用户名和密码
        List<User> findUser = manageUserDB.find("username", username);
        if(findUser.size()!=0){
            //用户名已经核对了，还需要核对密码
            User user = findUser.get(0);
            if(user.getPassword().equals(password)){
                //核对验证码
                if(num == inputNum){
                     nowUser = user;
                     status = 1;
                    flag = true;
                    log.info("登陆\t"+SystemEnum.SUCCESS.toString());
                }else{
                    System.out.println("验证码错误");
                    log.info("验证码\t"+SystemEnum.ERROR_MATCH.toString());
                }
            }else{
                log.info("密码\t"+SystemEnum.ERROR_MATCH.toString());
                System.out.println("密码错误");
            }
        }else {
            log.info("用户名\t"+SystemEnum.ERROR_MATCH.toString());
            System.out.println("用户名错误");
        }
        return flag;
    }
    public boolean signin(){    //注册
        log.info("MainSystem--signin()");
        //注册
        boolean flag = false;
        System.out.println("姓名 ：");
        String username = scanner.next();

        System.out.println("密码：");
        String password1 = scanner.next();

        System.out.println("再次输入密码：");
        String password2 = scanner.next();

        //核对正确的用户名和密码
        User user;
        List<User> findUser = manageUserDB.find("username", username);
        if(findUser.size()==0){
            //用户名已经核对了，还需要核对密码
            if(password1==null||password2==null) return false;
            if(password1.equals(password2)){
                //添加数据到数据库中
                user = new User(username,password1,0, new BigDecimal(0));
                manageUserDB.add(user);
                flag = true;
            }else{
                System.out.println("前后两次密码错误");
                String errorInput = scanner.nextLine();
                log.info("确认密码"+SystemEnum.ERROR_INPUT+errorInput);
            }
        }else {
            log.info("用户名"+SystemEnum.ERROR_REPEAT.toString());
            System.out.println("用户名已存在");
        }
        return flag;
    }
   /* public void printNewUsedCarInfo(){  //打印最新二手车信息

        log.info("MainSystem--printNewUsedCarInfo()");
        String printNewUsedCarInfoMenu = "1.收藏（必须登陆后才能进行收藏）\n" +
                "2.加入对比\n" +
                "3.购买（只能在登陆后才能看到该菜单项）\n" +
                "4.返回主菜单";

        //打印最新的二手车信息
        List<Car> lastestCars =  newUsedCars();

        //操作菜单
        int chose = -1; //-1为初始状态   -2为结束状态
        while (chose!=-2){
            menu(printNewUsedCarInfoMenu);
            chose = scanner.nextInt();
            switch (chose){
                case 1:
                    if(status==0){
                        if(!login()) {
                           break;
                        }
                    }
                    myCollect(findACar(lastestCars));
                    break;
                case 2:
                    log.info("加入对比");
                    if(status==0){
                        if(!login()) {
                           break;
                        }
                    }
                    addToContrast(findACar(lastestCars));
                    break;
                default:
                    chose = -2;
                    status = 0;
                    log.info("退出管理员菜单");
                    break;
            }
        }

    }*/


    public void printNewUsedCarInfo(){  //打印最新二手车信息
        //排序好的所有车列表
        List<Car> cars = manageCarDB.showLatest();

        //只取十个
        List<Car> tenCar = new ArrayList<>();
        //排序之后将超出10个的后面去掉
        for(int i=0;i<10;i++){
            tenCar.add(cars.get(i));
        }
        printCarMenu(tenCar);
    }

    //搜索车辆系统--菜单界面
    public void findACar(){
        int choose = -1;
        try {
            while (choose!=-2){
                System.out.println("请选择：");
                System.out.println("1.根据品牌搜索\n" +
                        "2.根据价格搜索\n" +
                        "3.根据上牌日期搜索\n" +
                        "4.返回上一界面");
                 choose = scanner.nextInt();
                switch (choose){
                    case 1:
                        searchBrand();
                        break;
                    case 2:
                        searchPrice();
                        break;
                    case 3:
                        searchDate();
                        break;
                    case 4:
                        default:
                        choose = -2;
                        log.info("退出搜索车辆系统的菜单界面");
                        break;
                }
            }
        }catch (Exception e){
            String errorInput = scanner.nextLine();
            log.info(SystemEnum.ERROR_INPUT+errorInput);
            System.out.println("退出搜索车辆系统");
            return;
        }

    }

    //搜索车辆系统--搜索车辆--根据品牌搜索
    public void searchBrand() {
        System.out.println("0.返回上一界面");
        manageBrandDB.printAll();
        System.out.println("请选择品牌：");
        try{
            int choose = scanner.nextInt();
            while (choose!=-2){
                if( choose != 0){
                    Brand brand = manageBrandDB.find("brandNum",Integer.toString(choose)).get(0);
                    searchCarType(brand);
                    choose = -2;
                }else {
                    findACar();
                }
            }
        }catch (Exception e){
            String errorInput = scanner.nextLine();
            log.info(SystemEnum.ERROR_INPUT+errorInput);
            System.out.println("非法输入，退出根据品牌搜索");
            return;
        }
    }
    //搜索车辆系统----根据品牌搜索--根据车型搜索
    public void searchCarType(Brand brand) {
        System.out.println("0.返回上一界面");
        manageCarTypeDB.printAll();
        System.out.println("请选择车型：");
        try{
            int choose = scanner.nextInt();
            List<Car> cars = new ArrayList<>();
            while (choose!=-2){
                if( choose != 0){
                    String content = brand.getBrandNum()+"/"+brand.getBrandName()+"/"+brand.getRemark();
                    List<Car> carT = manageCarDB.find("brand", content);
                    for (Car car:carT) {
                        if(Integer.parseInt(car.getCarType().getId())==choose){
                            cars.add(car);
                        }
                    }
                    printCarMenu(cars);
                    choose = -2;
                }else {
                    findACar();
                }
            }

        }catch (Exception e){
            String errorInput = scanner.nextLine();
            log.info(SystemEnum.ERROR_INPUT+errorInput);
            System.out.println("非法输入，退出根据车型搜索");
            return;
        }
    }

    //搜索车辆系统--搜索车辆--根据上牌日期搜索
    public void searchDate() {
        int choose = -1;
        while (choose!=-2){
            System.out.println("0.返回上一界面");
            System.out.println("1. 开始查询");
            System.out.println("请选择：");
            try{
                choose = scanner.nextInt();
                List<Car> cars = new ArrayList<>();
                switch (choose){
                    case 0:
                        findACar();
                        choose = -2;
                        break;
                    case 1:
                        System.out.println("请输入起始时间（格式如：2010-10-01）：");
                        String startTime = scanner.next();
                        System.out.println("请输入中止时间（格式如：2010-10-01）：");
                        String endTime = scanner.next();
                        List<Car> carT = manageCarDB.find("licensingTime>", endTime);
                        for (Car car:carT) {
                            if (!(manageCarDB.find("licensingTime>", startTime).contains(car))){
                                cars.add(car);
                            }
                        }
                        printCarMenu(cars);
                    default:
                        choose = -1;
                }
            }catch (Exception e){
                String errorInput = scanner.nextLine();
                log.info(SystemEnum.ERROR_INPUT+errorInput);
                System.out.println("退出根据上牌搜索");
                return;
            }
        }
    }

    //搜索车辆系统--搜索车辆--根据价格搜索
    public void searchPrice() {
        int choose = -1;
        while (choose!=-2){
            System.out.println("0.返回上一界面");
            System.out.println("1. 5万以下\n" +
                    "2. 5-10万\n" +
                    "3. 10-15万\n" +
                    "4. 15万以上");
            System.out.println("请选择价格范围：");
            try {
                choose = scanner.nextInt();
                List<Car> cars=null,cars1=null;
                switch (choose){
                    case 0:
                        findACar();
                        choose = -2;
                        break;
                    case 1:
                        cars = manageCarDB.find("price<=", String.valueOf(50000));
                        printCarMenu(cars);
                        cars = cars1 = null;
                        break;
                    case 2:
                        cars = manageCarDB.find("price<=", String.valueOf(100000));
                        cars1 = manageCarDB.find("price>", String.valueOf(50000));
                        cars.retainAll(cars1);
                        printCarMenu(cars);
                        cars = cars1 = null;
                        break;
                    case 3:
                        cars = manageCarDB.find("price<=", String.valueOf(150000));
                        cars1 = manageCarDB.find("price>", String.valueOf(100000));
                        cars.retainAll(cars1);
                        printCarMenu(cars);
                        cars = cars1 = null;
                        break;
                    case 4:
                        printCarMenu(cars);
                        cars = manageCarDB.find("price>", String.valueOf(150000));
                        printCarMenu(cars);
                        cars = cars1 = null;
                        break;
                    default:
                        choose = -1;
                }
            }catch (Exception e){
                String errorInput = scanner.nextLine();
                log.info(SystemEnum.ERROR_INPUT+errorInput);
                System.out.println("退出根据价格搜索");
                return;
            }
        }
    }
    //搜索车辆系统--打印信息的函数（参数：车辆列表）
    public void printCarMenu(List<Car> cars) {
        if(cars!=null&&cars.size()!=0) {
            log.info("MainSystem--printNewUsedCarInfo()");
            manageCarDB.printCar(cars);
            System.out.println("请选择（可了解详情）：");
            try{
                int choose = scanner.nextInt();
                while (choose != -2) {
                    if (choose != 0) {
                        //输出选择的完整信息
                        Car nowCar = cars.get(choose - 1);
                        System.out.println(nowCar);
                        //操作菜单
                        int chose = -1; //-1为初始状态   -2为结束状态
                        while (chose != -2) {
                            String printNewUsedCarInfoMenu = "1.收藏（必须登陆后才能进行收藏）\n" +
                                    "2.加入对比\n" +
                                    "3.购买（只能在登陆后才能看到该菜单项）\n" +
                                    "4.返回主菜单";
                           menu(printNewUsedCarInfoMenu);
                            chose = scanner.nextInt();
                            switch (chose) {
                                case 1:
                                    if(isLogin()) myCollect(nowCar);
                                    break;
                                case 2:
                                    if(isLogin()) addToContrast(nowCar);
                                    break;
                                case 3:
                                    //购买
                                    if(isLogin()) buyCar(nowCar);
                                    break;
                                default:
                                    chose = -2;
                                    status = 0;
                                    break;
                            }
                        }
                        choose = -2;
                    } else {
                        findACar();
                    }
                }
            }catch (Exception e){
                String errorInput = scanner.nextLine();
                log.info(SystemEnum.ERROR_INPUT+errorInput);
                System.out.println("非法输入 退出 搜索车辆--打印 系统");
                return;
            }

        }else {
            System.out.println("无符合情况车辆");
        }
    }

    public boolean isLogin(){
        //判断用户是否已经登陆
        if(status==0){
            if(!login()) {
                return false;
            }
        }
        return true;
    }
    public boolean buyCar(Car car){
        //获取车辆价格
        Double priceCar = car.getPrice();
        BigDecimal price = new BigDecimal(priceCar);
        //判断用户钱够不够
        BigDecimal balance = nowUser.getBalance();
        System.out.println("您的账户余额："+balance.doubleValue()+"\t该车价格："+price.doubleValue());
        if(balance.compareTo(price)==0||balance.compareTo(price)==1){
            //够
            //扣费
            balance = balance.subtract(price);
            manageUserDB.modify(nowUser, "balance", String.valueOf(balance.doubleValue()));
            System.out.println("购买成功");
            log.info(SystemEnum.SUCCESS.toString()+nowUser+"\t购买了\t"+car);
            return true;
        }else{
            System.out.println("您的账户余额("+balance.doubleValue()+"<"+price+")不足，是否要充值购买？true  or  false");
            try {
                boolean choose = scanner.nextBoolean();
                if(choose){
                    System.out.println("输入您的充值金额");
                    Double add = scanner.nextDouble();
                    log.info("add = "+add);
                    balance = balance.add(new BigDecimal(add));
                    System.out.println("充值后金额为："+balance.doubleValue());
                    manageUserDB.modify(nowUser, "balance", String.valueOf(balance.doubleValue()));
                    log.info("用户当前余额："+nowUser.getBalance());
                    System.out.println("充值成功，请重新进行购买");
                    log.info("余额充值"+SystemEnum.SUCCESS.toString());
                    return false;
                }else {
                    System.out.println("购买失败");
                    log.info(SystemEnum.ERROR_INEFFECTIVE);
                    return false;
                }

            }catch (Exception e){
                System.out.println("非法输出 退出购买");
                String errorInput = scanner.nextLine();
                log.info(SystemEnum.ERROR_INPUT+errorInput);
                return false;
            }

        }
    }

    //从列表中得到一辆二手车
    public Car findACar(List<Car> list){
        log.info("MainSystem--findACar()");
        //展示车辆列表
        System.out.println(list);
        System.out.println("输入车辆的车编码");
        String carNum = scanner.next();
        List<Car> findCarList = (new ManageCarDB(list)).find("carNum", carNum);
        Car car;
        if(findCarList!=null) {
            car = findCarList.get(0);
            log.info(SystemEnum.SUCCESS.toString());
           return car;
        }else{
            log.info(SystemEnum.ERROR_MATCH);
            return null;
        }
    }

   public void myCollect(){ //进入我的收藏系统
       if(!manageCollectDB.find(nowUser)){
           System.out.println("该用户没有收藏-退出我的收藏");
           return;
       }
       String myCollectMenu = "您可以进行如下操作：\n" +
               "1. 删除车辆\n" +
               "2. 删除该收藏夹\n" +
               "3. 车辆加入对比\n" +
               "4. 退出我的收藏\n";
       int chose = -1;
       while(chose!=-2){
           menu(myCollectMenu);
           manageCollectDB.printAUserCollect(nowUser);
           try{
               chose = scanner.nextInt();
               switch (chose){
                   case 1:
                       System.out.println("输入车辆的车辆编码");
                       String carNum = scanner.next();
                       List<Car> deleteCarList = (new ManageCarDB(manageCollectDB.getAUserCollect(nowUser))).find("carNum", carNum);
                       Car deleteCar;
                       if(deleteCarList!=null) {
                           deleteCar = deleteCarList.get(0);
                           manageCollectDB.delete(nowUser, deleteCar);
                           log.info("我的收藏夹中删除车辆--"+SystemEnum.SUCCESS);
                       }else{
                           log.info("我的收藏夹中删除车辆--"+SystemEnum.ERROR_MATCH+"\t"+SystemEnum.ERROR_INEFFECTIVE);
                       }
                       break;
                   case 2:
                       //删除收藏夹
                       manageCollectDB.delete(nowUser);
                       break;
                   case 3:
                       //某辆车加入对比中
                       System.out.println("输入车辆的车辆编码");
                       carNum = scanner.next();
                       List<Car> addToContrastCarList = (new ManageCarDB(manageCollectDB.getAUserCollect(nowUser))).find("carNum", carNum);
                       Car addToContrastCar;
                       if(addToContrastCarList!=null) {
                           addToContrastCar = addToContrastCarList.get(0);
                           //判断有没有对比
                           if(!manageContrastDB.find(nowUser)){
                               //没有
                               manageContrastDB.add(nowUser);
                           }
                           addToContrast(addToContrastCar);
                           log.info("我的对比中加入车辆--"+SystemEnum.SUCCESS);
                       }else{
                           log.info("我的对比中加入车辆--"+SystemEnum.ERROR_MATCH);
                       }
                       break;
                   case 4:
                       default:
                        log.info("退出我的收藏"+SystemEnum.SUCCESS);
                        chose = -2;
                           break;
               }
           }catch (Exception e){
               String errorInput = scanner.nextLine();
               log.info("我的收藏夹系统--"+SystemEnum.ERROR_INPUT+errorInput);
               chose = -1;
           }
       }
   }

    public void myCollect(Car car){    //加入车辆到我的收藏
        log.info("MainSystem--myCollect()");
        //判断该用户是否拥有收藏
        if(!manageCollectDB.find(nowUser)) {
            //不存在，添加键值对
            if (manageCollectDB.add(nowUser)) {
                log.info("添加键值对--" + SystemEnum.SUCCESS.toString());
            }
        }
        if(manageCollectDB.add(nowUser, car)){
            log.info("加入收藏--"+SystemEnum.SUCCESS.toString());
        }else{
            log.info("加入收藏--"+SystemEnum.ERROR_INEFFECTIVE.toString());
        }
    }           //直接将一辆车加入收藏

    //对比
    //将一辆车加入我的对比
    public void addToContrast(Car car){
        log.info("将一辆车加入我的对比");
        if(manageContrastDB.add(nowUser,car )){
            log.info(SystemEnum.SUCCESS.toString());
            System.out.println("=============================");
            System.out.println(manageContrastDB.getAUserContrast(nowUser));
        }else log.info(SystemEnum.ERROR_INEFFECTIVE.toString());
    }
    //打印我的对比
    public void printMyContrast(){
        log.info("打印我的对比");
        manageContrastDB.printAUserContrast(nowUser);
    }

    //对比系统
    public void contrastCars(){ //对比车辆
        log.info("MainSystem--contrastCars()");
        String contrastCarsMenu = "1.查看对比信息\n" +
                "2.删除对比-车辆\n" +
                "3.删除对比\n"+
                "4.返回上一级菜单";
        int chose = -1;
        while(chose!=-2){
            menu(contrastCarsMenu);
            chose =scanner.nextInt();
            switch (chose){
                case 1:
                    //查看对比信息
                    printMyContrast();
                    break;
                case 2:
                    //删除对比车辆
                    Contrast contrast = manageContrastDB.getAUserContrast(nowUser);
                    Set<Car> set = null ;
                    List<Car> cars1 = null;
                    if(contrast!=null){
                        set = contrast.getSet();
                        if(set!=null){
                            cars1 = new ArrayList(set);
                            if(cars1!=null){
                                Car deleteCar = findACar(cars1);
                                deleteContrastCar(deleteCar);
                                break;
                            }
                        }
                    }
                    System.out.println("对比集合为空 不可删除 返回上一级");
                    break;
                case 3:
                    deleteContrastCar();
                    break;
                case 4:
                    default:
                        log.info("退出对比系统");
                        chose = -2;
                    break;
            }
        }
    }

    //删除对比车辆---车辆
    public void deleteContrastCar(Car car){
        if(manageContrastDB.delete(nowUser, car)){
            log.info(SystemEnum.SUCCESS.toString());
        }else{
            log.info(SystemEnum.ERROR_INEFFECTIVE.toString());
        }
    }
    //删除对比
    public void deleteContrastCar(){
        if(manageContrastDB.delete(nowUser)){
            log.info(SystemEnum.SUCCESS.toString());
        }else log.info(SystemEnum.ERROR_INEFFECTIVE.toString());
    }
    public void management(){   //后台管理
        log.info("MainSystem-- management()");
        log.info(SystemEnum.SUCCESS.toString());

        System.out.println("1.品牌管理\n" +
                "2.车型管理\n" +
                "3.发布车辆信息");
        Scanner scanner = new Scanner(System.in);
        int choose = scanner.nextInt();
        switch (choose){
            case 1:
                //品牌管理
                System.out.println("请输入想要添加的品牌：");
                String newBrandName = scanner.next();
                Brand brand = new Brand(manageBrandDB.getListSize()+1,newBrandName,null);
                manageBrand(brand);
                break;
            case 2:
                //车型管理
                manageCarType();
                break;
            case 3:
                //发布车辆
                releaseCarInfo();
                break;
        }
        log.info(SystemEnum.ERROR_INEFFECTIVE.toString());
    }

    //品牌管理
    public void manageBrand(Brand brand){
        manageBrandDB.add(brand);
    }
    //车型管理
    public void manageCarType(){
        System.out.println("所有车型如下：");
        List<CarType> brandsList = DataBase.getInstance().getCarTypesList();
        for (int i = 0; i < brandsList.size(); i++) {
            System.out.println(brandsList.get(i));
        }
        int choose;
        System.out.println("按1添加车型，按2删除车型");
        try{
            choose = scanner.nextInt();
            switch (choose){
                case 1:
                    //添加车型
                    System.out.println("请输入你要添加的车型：");
                    String carType = scanner.next();
                    manageCarTypeDB.add(new CarType(String.valueOf(manageCarTypeDB.getListSize()+1),carType));
                    break;
                case 2:
                    //删除车型
                    System.out.println("请输入你要删除的车型编号：");
                    carType = scanner.next();
                    List<CarType> carTypes = manageCarTypeDB.find("id", carType);
                    if(carTypes!=null){
                        manageCarTypeDB.delete(carTypes.get(0));
                        log.info(SystemEnum.SUCCESS);
                    }else log.info(SystemEnum.ERROR_INEFFECTIVE);
                    break;
            }
        }catch (Exception e){
            String errorInput = scanner.nextLine();
            log.info(SystemEnum.ERROR_INPUT+errorInput);
            System.out.println("非法输入，退出车辆管理");
            return;
        }
    }

    //发布车辆信息
    public void releaseCarInfo(){
        //获取当前系统时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String timeInfo = simpleDateFormat.format(date);
        System.out.println("请完善车辆的详细信息");
        System.out.println("请选择品牌");
        List<Brand> brandsList = dataBase.getBrandsList();
        for (int i = 0; i < brandsList.size(); i++) {
            System.out.println(i+" "+brandsList.get(i).getBrandName());
        }
        try{
            int i = scanner.nextInt();
            String brandName = brandsList.get(i).getBrandName();
            System.out.println("请选择车型");
            List<CarType> carTypesList = dataBase.getCarTypesList();
            for (int k = 0; k < carTypesList.size(); k++) {
                System.out.println(k+" "+carTypesList.get(k).getName());
            }
            int j =scanner.nextInt();
            String carType = carTypesList.get(j).getName();
            System.out.println(brandName + "\t" + carType + "\t" +"发布成功，发布时间为："+timeInfo);

        }catch (Exception e){
            String errorInput = scanner.nextLine();
            log.info(SystemEnum.ERROR_INPUT+errorInput);
            return;
        }
    }
}
